﻿using LJX.SmartPark.Common.Extensions;
using LJX.SmartPark.Common.ResponseOutput;
using LJX.SmartPark.Domain.Area;
using LJX.SmartPark.Service.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LJX.SmartPark.Service.Area
{
    public class ParkingRecordService:IParkingRecordService
    {
        private readonly IRepository<ParkingRecord> _ParkingRecordService;

        public ParkingRecordService(IRepository<ParkingRecord> ParkingRecordService)
        {
            _ParkingRecordService = ParkingRecordService;
        }

        public async Task<Response<bool>> ParkingRecordAdd(ParkingRecord input)
        {
            var result = await _ParkingRecordService.InsertAsyncById(input.MapTo<ParkingRecord>());

            return Response<bool>.Ok(result> 0);
        }

        public async Task<Response<bool>> ParkingRecordDelete(ParkingRecord input)
        {
            var result = await _ParkingRecordService.DeleteByIdAsync(input.MapTo<ParkingRecord>());
            return Response<bool>.Ok(result > 0);
        }

        public async Task<Response<bool>> ParkingRecordDeleteDatas(string[] ids)
        {
            var dtos = _ParkingRecordService.GetListQuery().Where(m => ids.Contains(m.Id.ToString()));
            var result = await _ParkingRecordService.DeleteAsync(dtos.ToArray());
            return Response<bool>.Ok(result > 0);
        }

        public async Task<Response<bool>> ParkingRecordUpdate(ParkingRecord input)
        {
            var result = _ParkingRecordService.UpdateAsync(input.MapTo<ParkingRecord>());

            return Response<bool>.Ok(result.Result > 0);
        }

        public async Task<Response<List<ParkingRecord>>> GetParkingRecordAsync()
        {
            var ParkingRecord = await _ParkingRecordService.GetAllListAsync();
            var result = ParkingRecord.MapToList<ParkingRecord>();
            return Response<List<ParkingRecord>>.Ok(result);
        }

        public Response<ParkingRecord> GetParkingRecordData(ParkingRecord input)
        {
            var ParkingRecord = _ParkingRecordService.GetListQuery().FirstOrDefault(m => m.Id.ToString() == input.CarNum);
            var result = ParkingRecord.MapTo<ParkingRecord>();
            return Response<ParkingRecord>.Ok(result);
        }
    }
}
